package com.gzyz.cheetah.controller;


import com.gzyz.cheetah.annotations.UserJwtIntercept;
import com.gzyz.cheetah.entity.dto.CommentDTO;
import com.gzyz.cheetah.entity.dto.PageDTO;
import com.gzyz.cheetah.entity.table.Comment;
import com.gzyz.cheetah.service.ICommentService;
import com.gzyz.cheetah.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author xclhove
 * @since 2023-11-06
 */

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    ICommentService iCommentService;
    @PostMapping("/addComment")
    @UserJwtIntercept
    public Result<Object> register(@RequestBody Comment comment) {
        iCommentService.addComment(comment);
        return Result.success(comment);
    }

    @PostMapping("/deleteCommentById/{id}")
    public Result <Object> deleteCommentById(@PathVariable Integer id) {
        iCommentService.deleteCommentById(id);
        return Result.success();
    }

    @PostMapping("/update")
    public Result <Object> update(@RequestBody Comment comment) {
        iCommentService.updateComment(comment);
        return Result.success();
    }

    @GetMapping("/pageList")
    public Result <PageDTO<CommentDTO>> pageDocumentComments(@RequestParam Integer documentId, @RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        PageDTO<CommentDTO> pageDTO = iCommentService.pageDocumentComments(documentId,pageNo,pageSize);
        return Result.success(pageDTO);
    }

}
